<template>
  <div class="meal">
    <cu-header :height="80" />
    <div class="meal-container container">
      <div>
        <div class="panel-title">{{ $t('meal.1') }}</div>
        <div class="goods-info">
          <div class="goods-info-l">
            <img :src="domain + showImg" alt="" />
          </div>
          <div class="goods-info-r">
            <div class="goods-row">
              <span class="goods-label">{{ $t('meal.2') }}：</span>
              <span class="goods-name">{{ goodsInfo.name }}</span>
            </div>
            <div class="goods-row">
              <span class="goods-label">{{ $t('meal.3') }}：</span>
              <span class="goods-desc">{{ format(goodsInfo.mainLimit )}}</span>
            </div>
            <div class="goods-row">
              <span class="goods-label">{{ $t('meal.4') }}：</span>
              <span class="goods-desc">{{ format(goodsInfo.recommendLimit) }}</span>
            </div>
            <div class="goods-row">
              <span class="goods-label">{{ $t('meal.5') }}：</span>
              <span class="goods-desc">{{ goodsInfo.topCount }}</span>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div style="border-top:70px solid #f2f2f2"> </div>
    <div class="meal-container container" style="margin-top:20px">
      <div>
        <div class="panel-title">Detail</div>
        <div class="goods-info">
          <el-collapse v-model="activeNames" style="width:70%">
            <el-collapse-item v-for="(item,index) in list" :key="index" :title="item.productName" :name="index">
              <el-row>
              <el-col :span="4">
                <div>Count：<span style="color:#fb8c24">{{ item.num }}</span></div>
              </el-col>
              <el-col :span="5">
                <div>Total：<span style="color:#fb8c24">{{ item.totalPrice | num2Money }} KZ</span></div>
              </el-col>
              <el-col :span="4">Type：{{ item.type }}</el-col>
              <el-col :span="3">Unit：{{item.unit}}</el-col>
            </el-row>
            </el-collapse-item>
          </el-collapse>
        </div>
      </div>
    </div>
    <cu-footer style="border-top:70px solid #f2f2f2" />
  </div>
</template>
<script>
import CuHeader from '@/components/header';
import CuFooter from '@/components/footer/index3';
import { Domain } from '@/constants';
import Api from '@/api';
export default {
  name: 'Meal',
  components: { CuHeader, CuFooter },
  data() {
    return {
      domain: Domain,
      id: '',
      detail: { },
      showImg: '',
      goodsInfo:{},
      list:[],
      activeNames: []
    };
  },
  created() {
    this.loadDetail(this.$route.params.id);
  },

  methods: {
    // 转换时间格式
    format(time){
      if (time){
        var date = new Date(time);
        var year=date.getFullYear();
        var month=date.getMonth()+1;
        var date1=date.getDate();
        var h = date.getHours();
        var mm = date.getMinutes();
        var s = date.getSeconds();
        return year+"-"+month+"-"+date1+"  "+h+": "+mm+": "+s;
      }else {
        return ""
      }
    },
    loadDetail(id) {
      Api.payOrderDetail(id).then((res) => {
        console.log(res)
        this.detail = res;
        this.goodsInfo = JSON.parse(this.detail.goodsInfo)
        this.list = JSON.parse(this.detail.content)
        // 默认全部展开
        this.activeNames = []
        this.list.forEach((item,index)=>{
          this.activeNames.push(index)
        })
        this.showImg = this.goodsInfo.imgList.length > 0 ?JSON.parse(this.goodsInfo.imgList)[0] : '';
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.meal-out{
  height: 170px;
}
// .container{
//   // width: 80%;
// }
.meal-container {
  // width: 80%;
  margin-top: 95px;
  .panel-title {
    font-size: 24px;
    color: #333;
    font-weight: bold;
    margin-bottom: 30px;
  }
  .goods-info {
    display: flex;
    margin-bottom: 30px;
  }
  .goods-info-l {
    flex: none;
    margin-right: 30px;
    img {
      width: 200px;
      height: 200px;
      display: inline-block;
      border-radius: 6px;
      object-fit: cover;

    }
  }
  .goods-info-r {
    flex: auto;
    width: 0;
    .goods-row {
      margin-bottom: 20px;
      background-color: #fb8c24;

      padding: 10px;
      .goods-label {
        color: #595959;
        font-size: 16px;
        display: inline-block;
        width: 30em;
        color: #fff;
      }
      .goods-name {
        font-weight: bold;
        font-size: 18px;
        // color: #333;
        color: #fff;
      }
      .goods-desc {
        // color: #333;
        color: #fff;
      }
    }
  }
}
.meal-left {
  margin-right: 32px;
}
.meal-title {
  position: relative;
  color: #262626;
  font-size: 48px;
  font-family: Source Han Sans CN;
  font-weight: bold;
  letter-spacing: 5px;
  margin-bottom: 100px;
  transform-style: preserve-3d;
  margin-top: 30px;
}
.meal-title::before {
  content: attr(data-upper);
  font-weight: bold;
  font-size: 116px;
  color: #f2f2f2;
  position: absolute;
  left: -25px;
  top: -50px;
  transform: translateZ(-1px);
}
.meal-title::after {
  content: attr(data-desc);
  font-weight: bold;
  font-size: 20px;
  color: #e8e8e8;
  position: absolute;
  left: 0px;
  top: 93px;
  transform: translateZ(-1px);
  letter-spacing: 0;
}
.meal-desc p {
  color: #333;
  font-weight: bold;
  font-size: 16px;
  padding-left: 15px;
  margin-top: 20px;
  margin-bottom: 20px;
}
.meal-desc ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.meal-desc li {
  list-style: none;
  color: #595959;
  font-size: 14px;
  margin-bottom: 24px;
  line-height: 19px;
}
.li-dot {
  width: 4px;
  height: 4px;
  border-radius: 4px;
  background-color: #fb8c24;
  display: inline-block;
  margin-right: 10px;
  vertical-align: middle;
}
.meal-item {
  margin-right: 32px;
  width: calc((100% - 64px) / 3);
  border: 1px solid #e8e8e8;
  box-sizing: border-box;
  padding: 32px 20px;
  height: 565px;
  text-align: center;
}
.meal-item:last-child {
  margin-right: 0;
}
.meal-img {
  width: 56px;
  height: 56px;
}
.meal-name {
  margin-top: 30px;
  color: #333333;
  font-size: 24px;
  font-weight: bold;
}
.meal-days {
  color: #595959;
  font-size: 14px;
  margin: 30px auto;
  display: block;
  text-align:left;

  width: 140px;
}
.meal-detail {
  list-style: none;
  margin: 0;
  padding: 0;
}
.meal-detail li {
  list-style: none;
  text-align:left;
  // width:30%;
  width: 140px;
  margin: 0 auto;
  padding: 0;
  margin-bottom: 24px;
}
.meal-detail li .meal-input {
  width: 60px;
  margin-right: 10px;
  text-align: center;
}
.meal-detail li img {
  display: inline-block;
  width: 16px;
  height: 16px;
}
.meal-buy button {
  // width: 141px;
  height: 40px;
  background: #fb7924;
  border-radius: 4px;
  color: #fff;
  line-height: 38px;
  border: none;
  outline: none;
  padding: 0 10px;
  cursor: pointer;
  &:hover {
    background: #fdaf66;
  }
  &:active {
    background: #e27e20;
  }
}
</style>
